<template>
  <basic-dialog
    :width="'40%'"
    :visible.sync="transferVisible"
    :title="'跨区域转派'"
    :handle-close="onCancel"
    :handle-ok="handleConfirm"
  >
    <el-form
      ref="formData"
      :model="formData"
      :rules="formValidate"
    >
      <el-form-item label="销售区域" prop="areaId">
        <el-select
          v-model.trim="formData.areaId"
          placeholder="请选择销售区域"
          filterable
        >
          <el-option
            v-for="item in areaOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </basic-dialog>
</template>
<script>
import BasicDialog from '@/components/BasicDialog';
export default {
  components: {
    BasicDialog
  },
  props: {
    areaOptions: {
      type: Array,
      required: true
    },
    transferVisible: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      formData: {
        areaId: '',
      },
      formValidate: {
        areaId: [
          { required: true, message: '请选择销售区域', trigger: 'change' }
        ]
      }
    };
  },
  methods: {
    onCancel () {
      if (this.$refs.formData) {
        this.$refs.formData.resetFields();
      }
      this.formData = {}
      this.$emit('update:transferVisible', false);
    },
    handleConfirm () {
      this.$refs['formData'].validate((valid) => {
        if (valid) {
          this.$emit('handleTransfer', 3, this.formData.areaId)
          this.onCancel()
        }
      });
    }
  }
};
</script>
<style scoped>
.el-select, .el-date-editor.el-input {
  width: 100%;
}
</style>
